import Vue from 'vue'
import VueRouter from 'vue-router'

import beforeEach from './beforeEach'

Vue.use(VueRouter)

const routes = [
  /**首页路由 */
  {
    path: '/',
    name: 'home',
    component: () => import('@/layout'),
  },
  // 搜索
  {
    path: '/search',
    name: 'search',
    component: () => import('@/layout/search'),
  },
  // 详情页
  {
    path: '/detailpage',
    name: 'detailpage',
    component: () => import('@/layout/detailpage'),
    redirect: '/detailpage/introduce',
    children: [
      {
        path: '/detailpage/introduce',
        name: 'detailpage-introduce',
        component: () => import('@/layout/detailpage/components/details/components/Introduction'),
      },
      {
        path: '/detailpage/comment',
        name: 'detailpage-comment',
        component: () => import('@/layout/detailpage/components/details/components/GoodsComment'),
      },
      {
        path: '/detailpage/guarantee',
        name: 'detailpage-guarantee',
        component: () => import('@/layout/detailpage/components/details/components/Guarantee'),
      },
    ],
  },
  // 加购页
  {
    path: '/add-purchase',
    name: 'add-purchase',
    component: () => import('@/layout/add-purchase'),
    meta: {
      loged: true,
    },
  },
  /** 登录路由*/
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '@/layout/login'),
  },
  // 注册
  {
    path: '/enroll',
    name: 'enroll',
    component: () => import('@/layout/login/enroll'),
  },
  /**购物车路由 */
  {
    path: '/shopping-cart',
    name: 'shopping-cart',
    meta: {
      loged: true,
    },
    component: () => import('@/layout/shopping-cart'),
  },
  // 评论页
  {
    path: '/comment-reply',
    name: 'comment-reply',
    component: () => import('@/layout/Comment-reply'),
  },
  // 评价商品
  {
    path: '/evaluation-order',
    name: 'evaluation-order',
    component: () => import('@/layout/evaluation-order'),
    meta: {
      loged: true,
    },
  },
  /**个人信息路由 */
  {
    path: '/personal-data',
    name: 'personal-data',
    component: () => import('@/layout/personal-data'),
    meta: {
      loged: true,
    },
  },
  /**待评价 */
  {
    path: '/to-evaluated',
    name: 'to-evaluated',
    component: () => import('@/layout/ToEvaluated'),
    meta: {
      loged: true,
    },
  },
]

const router = new VueRouter({
  routes,
})

beforeEach(router)

export default router
